package o;

import com.huawei.hms.framework.network.restclient.hianalytics.HianalyticsData;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nullable;

public final class fug {
    private static final Pattern ˊ = Pattern.compile("(?i)(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec).*");
    private static final Pattern ˎ = Pattern.compile("(\\d{1,2})[^\\d]*");
    private static final Pattern ˏ = Pattern.compile("(\\d{2,4})[^\\d]*");
    private static final Pattern ॱ = Pattern.compile("(\\d{1,2}):(\\d{1,2}):(\\d{1,2})[^\\d]*");
    private final String ʻ;
    private final String ʼ;
    private final long ʽ;
    private final boolean ˊॱ;
    private final String ˋ;
    private final boolean ˋॱ;
    private final boolean ॱˊ;
    private final boolean ॱॱ;
    private final String ᐝ;

    private fug(String str, String str2, long j, String str3, String str4, boolean z, boolean z2, boolean z3, boolean z4) {
        this.ˋ = str;
        this.ʻ = str2;
        this.ʽ = j;
        this.ʼ = str3;
        this.ᐝ = str4;
        this.ॱॱ = z;
        this.ˊॱ = z2;
        this.ॱˊ = z3;
        this.ˋॱ = z4;
    }

    public String ˏ() {
        return this.ˋ;
    }

    public String ˊ() {
        return this.ʻ;
    }

    private static boolean ˊ(String str, String str2) {
        if (str.equals(str2)) {
            return true;
        }
        if (str.endsWith(str2) && str.charAt((str.length() - str2.length()) - 1) == '.' && !fvg.ॱ(str)) {
            return true;
        }
        return false;
    }

    @Nullable
    public static fug ˋ(fur o_fur, String str) {
        return ॱ(System.currentTimeMillis(), o_fur, str);
    }

    @Nullable
    static fug ॱ(long j, fur o_fur, String str) {
        int length = str.length();
        int ˊ = fvg.ˊ(str, 0, length, ';');
        int ˊ2 = fvg.ˊ(str, 0, ˊ, '=');
        if (ˊ2 == ˊ) {
            return null;
        }
        String ˎ = fvg.ˎ(str, 0, ˊ2);
        if (ˎ.isEmpty() || fvg.ˋ(ˎ) != -1) {
            return null;
        }
        String ˎ2 = fvg.ˎ(str, ˊ2 + 1, ˊ);
        if (fvg.ˋ(ˎ2) != -1) {
            return null;
        }
        String ˎ3;
        long j2 = 253402300799999L;
        long j3 = -1;
        String str2 = null;
        String str3 = null;
        boolean z = false;
        boolean z2 = false;
        boolean z3 = true;
        boolean z4 = false;
        ˊ++;
        while (ˊ < length) {
            long j4;
            int ˊ3 = fvg.ˊ(str, ˊ, length, ';');
            int ˊ4 = fvg.ˊ(str, ˊ, ˊ3, '=');
            String ˎ4 = fvg.ˎ(str, ˊ, ˊ4);
            if (ˊ4 < ˊ3) {
                ˎ3 = fvg.ˎ(str, ˊ4 + 1, ˊ3);
            } else {
                ˎ3 = "";
            }
            if (ˎ4.equalsIgnoreCase("expires")) {
                try {
                    j2 = ˋ(ˎ3, 0, ˎ3.length());
                    z4 = true;
                    ˎ3 = str2;
                    j4 = j2;
                } catch (IllegalArgumentException e) {
                    ˎ3 = str2;
                    j4 = j2;
                }
            } else {
                if (ˎ4.equalsIgnoreCase("max-age")) {
                    try {
                        j3 = ˊ(ˎ3);
                        z4 = true;
                        ˎ3 = str2;
                        j4 = j2;
                    } catch (NumberFormatException e2) {
                        ˎ3 = str2;
                        j4 = j2;
                    }
                } else {
                    if (ˎ4.equalsIgnoreCase(HianalyticsData.DOMAIN)) {
                        try {
                            ˎ3 = ˏ(ˎ3);
                            z3 = false;
                            j4 = j2;
                        } catch (IllegalArgumentException e3) {
                            ˎ3 = str2;
                            j4 = j2;
                        }
                    } else {
                        if (ˎ4.equalsIgnoreCase("path")) {
                            str3 = ˎ3;
                            ˎ3 = str2;
                            j4 = j2;
                        } else {
                            if (ˎ4.equalsIgnoreCase("secure")) {
                                z = true;
                                ˎ3 = str2;
                                j4 = j2;
                            } else {
                                if (ˎ4.equalsIgnoreCase("httponly")) {
                                    z2 = true;
                                    ˎ3 = str2;
                                    j4 = j2;
                                } else {
                                    ˎ3 = str2;
                                    j4 = j2;
                                }
                            }
                        }
                    }
                }
            }
            String str4 = ˎ3;
            ˊ = ˊ3 + 1;
            j2 = j4;
            str2 = str4;
        }
        if (j3 == Long.MIN_VALUE) {
            j3 = Long.MIN_VALUE;
        } else if (j3 != -1) {
            if (j3 <= 9223372036854775L) {
                j3 *= 1000;
            } else {
                j3 = Long.MAX_VALUE;
            }
            j3 += j;
            if (j3 < j || j3 > 253402300799999L) {
                j3 = 253402300799999L;
            }
        } else {
            j3 = j2;
        }
        ˎ3 = o_fur.ʻ();
        if (str2 == null) {
            str2 = ˎ3;
        } else if (!ˊ(ˎ3, str2)) {
            return null;
        }
        if (ˎ3.length() != str2.length() && fww.ˊ().ˎ(str2) == null) {
            return null;
        }
        String substring;
        if (str3 == null || !str3.startsWith("/")) {
            str3 = o_fur.ʽ();
            ˊ = str3.lastIndexOf(47);
            substring = ˊ != 0 ? str3.substring(0, ˊ) : "/";
        } else {
            substring = str3;
        }
        return new fug(ˎ, ˎ2, j3, str2, substring, z, z2, z3, z4);
    }

    private static long ˋ(String str, int i, int i2) {
        int ˏ = ˏ(str, i, i2, false);
        int i3 = -1;
        int i4 = -1;
        int i5 = -1;
        int i6 = -1;
        int i7 = -1;
        int i8 = -1;
        Matcher matcher = ॱ.matcher(str);
        while (ˏ < i2) {
            int ˏ2 = ˏ(str, ˏ + 1, i2, true);
            matcher.region(ˏ, ˏ2);
            if (i3 == -1 && matcher.usePattern(ॱ).matches()) {
                i3 = Integer.parseInt(matcher.group(1));
                i4 = Integer.parseInt(matcher.group(2));
                i5 = Integer.parseInt(matcher.group(3));
            } else if (i6 == -1 && matcher.usePattern(ˎ).matches()) {
                i6 = Integer.parseInt(matcher.group(1));
            } else if (i7 == -1 && matcher.usePattern(ˊ).matches()) {
                i7 = ˊ.pattern().indexOf(matcher.group(1).toLowerCase(Locale.US)) / 4;
            } else if (i8 == -1 && matcher.usePattern(ˏ).matches()) {
                i8 = Integer.parseInt(matcher.group(1));
            }
            ˏ = ˏ(str, ˏ2 + 1, i2, false);
        }
        if (i8 >= 70 && i8 <= 99) {
            i8 += 1900;
        }
        if (i8 >= 0 && i8 <= 69) {
            i8 += 2000;
        }
        if (i8 < 1601) {
            throw new IllegalArgumentException();
        } else if (i7 == -1) {
            throw new IllegalArgumentException();
        } else if (i6 < 1 || i6 > 31) {
            throw new IllegalArgumentException();
        } else if (i3 < 0 || i3 > 23) {
            throw new IllegalArgumentException();
        } else if (i4 < 0 || i4 > 59) {
            throw new IllegalArgumentException();
        } else if (i5 < 0 || i5 > 59) {
            throw new IllegalArgumentException();
        } else {
            Calendar gregorianCalendar = new GregorianCalendar(fvg.ॱॱ);
            gregorianCalendar.setLenient(false);
            gregorianCalendar.set(1, i8);
            gregorianCalendar.set(2, i7 - 1);
            gregorianCalendar.set(5, i6);
            gregorianCalendar.set(11, i3);
            gregorianCalendar.set(12, i4);
            gregorianCalendar.set(13, i5);
            gregorianCalendar.set(14, 0);
            return gregorianCalendar.getTimeInMillis();
        }
    }

    private static int ˏ(String str, int i, int i2, boolean z) {
        for (int i3 = i; i3 < i2; i3++) {
            Object obj;
            char charAt = str.charAt(i3);
            Object obj2 = ((charAt >= ' ' || charAt == '\t') && charAt < '' && ((charAt < '0' || charAt > '9') && ((charAt < 'a' || charAt > 'z') && ((charAt < 'A' || charAt > 'Z') && charAt != ':')))) ? null : 1;
            if (z) {
                obj = null;
            } else {
                obj = 1;
            }
            if (obj2 == obj) {
                return i3;
            }
        }
        return i2;
    }

    private static long ˊ(String str) {
        try {
            long parseLong = Long.parseLong(str);
            if (parseLong <= 0) {
                return Long.MIN_VALUE;
            }
            return parseLong;
        } catch (NumberFormatException e) {
            if (!str.matches("-?\\d+")) {
                throw e;
            } else if (str.startsWith("-")) {
                return Long.MIN_VALUE;
            } else {
                return Long.MAX_VALUE;
            }
        }
    }

    private static String ˏ(String str) {
        if (str.endsWith(".")) {
            throw new IllegalArgumentException();
        }
        if (str.startsWith(".")) {
            str = str.substring(1);
        }
        String ˏ = fvg.ˏ(str);
        if (ˏ != null) {
            return ˏ;
        }
        throw new IllegalArgumentException();
    }

    public static List<fug> ˋ(fur o_fur, fui o_fui) {
        List ˎ = o_fui.ˎ("Set-Cookie");
        List list = null;
        int size = ˎ.size();
        for (int i = 0; i < size; i++) {
            fug ˋ = ˋ(o_fur, (String) ˎ.get(i));
            if (ˋ != null) {
                List arrayList;
                if (list == null) {
                    arrayList = new ArrayList();
                } else {
                    arrayList = list;
                }
                arrayList.add(ˋ);
                list = arrayList;
            }
        }
        if (list != null) {
            return Collections.unmodifiableList(list);
        }
        return Collections.emptyList();
    }

    public String toString() {
        return ॱ(false);
    }

    String ॱ(boolean z) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(this.ˋ);
        stringBuilder.append('=');
        stringBuilder.append(this.ʻ);
        if (this.ˋॱ) {
            if (this.ʽ == Long.MIN_VALUE) {
                stringBuilder.append("; max-age=0");
            } else {
                stringBuilder.append("; expires=").append(fvs.ˊ(new Date(this.ʽ)));
            }
        }
        if (!this.ॱˊ) {
            stringBuilder.append("; domain=");
            if (z) {
                stringBuilder.append(".");
            }
            stringBuilder.append(this.ʼ);
        }
        stringBuilder.append("; path=").append(this.ᐝ);
        if (this.ॱॱ) {
            stringBuilder.append("; secure");
        }
        if (this.ˊॱ) {
            stringBuilder.append("; httponly");
        }
        return stringBuilder.toString();
    }

    public boolean equals(@Nullable Object obj) {
        if (!(obj instanceof fug)) {
            return false;
        }
        fug o_fug = (fug) obj;
        if (o_fug.ˋ.equals(this.ˋ) && o_fug.ʻ.equals(this.ʻ) && o_fug.ʼ.equals(this.ʼ) && o_fug.ᐝ.equals(this.ᐝ) && o_fug.ʽ == this.ʽ && o_fug.ॱॱ == this.ॱॱ && o_fug.ˊॱ == this.ˊॱ && o_fug.ˋॱ == this.ˋॱ && o_fug.ॱˊ == this.ॱˊ) {
            return true;
        }
        return false;
    }

    public int hashCode() {
        int i;
        int i2 = 0;
        int hashCode = (((((((((this.ˋ.hashCode() + 527) * 31) + this.ʻ.hashCode()) * 31) + this.ʼ.hashCode()) * 31) + this.ᐝ.hashCode()) * 31) + ((int) (this.ʽ ^ (this.ʽ >>> 32)))) * 31;
        if (this.ॱॱ) {
            i = 0;
        } else {
            i = 1;
        }
        hashCode = (i + hashCode) * 31;
        if (this.ˊॱ) {
            i = 0;
        } else {
            i = 1;
        }
        hashCode = (i + hashCode) * 31;
        if (this.ˋॱ) {
            i = 0;
        } else {
            i = 1;
        }
        i = (i + hashCode) * 31;
        if (!this.ॱˊ) {
            i2 = 1;
        }
        return i + i2;
    }
}
